import request from '@/utils/request'

const api = {
  user: '/system/user',
  tenant: '/system/tenant',
  dept: '/system/dept',
  role: '/system/role',
  menu: '/system/menu'
}

export function getUserList (data) {
  return request({
    url: api.user + '/list',
    method: 'post',
    data
  })
}

export function changeStatus ({ id, status }) {
  return request({
    url: api.user + '/changeStatus' + `/${id}/${status}`,
    method: 'put'
  })
}

export function delUser (userIds) {
  return request({
    url: api.user + '/batchDel',
    method: 'delete',
    data: JSON.stringify(userIds)
  })
}

export function userResetPassword (data) {
  return request({
    url: api.user + '/resetPassword',
    method: 'put',
    data
  })
}

export function tenantInfo () {
  return request({
    url: api.tenant + '/info',
    method: 'get'
  })
}

export function findDeptTree (tenantCode) {
  return request({
    url: api.dept + `/findDeptTree/${tenantCode}`,
    method: 'get'
  })
}

export function findRoleByTenantCode (tenantCode) {
  return request({
    url: api.role + `/findRoleByTenantCode/${tenantCode}`,
    method: 'get'
  })
}

export function addUser (data) {
  return request({
    url: api.user + '/add',
    method: 'post',
    data
  })
}

export function editUser (data) {
  return request({
    url: api.user + '/edit',
    method: 'put',
    data
  })
}

export function roleList (data) {
  return request({
    url: api.role + '/list',
    method: 'post',
    data
  })
}

export function changeRoleStatus ({ id, status }) {
  return request({
    url: api.role + '/changeRoleStatus' + `/${id}/${status}`,
    method: 'put'
  })
}

export function delRole (roleIds) {
  return request({
    url: api.role + '/batchDelRole',
    method: 'delete',
    data: JSON.stringify(roleIds)
  })
}

export function addRole (data) {
  return request({
    url: api.role + '/addRole',
    method: 'post',
    data
  })
}

export function roleDetails ({ id }) {
  return request({
    url: api.role + '/roleDetails' + `/${id}`,
    method: 'get'
  })
}

export function editRole (data) {
  return request({
    url: api.role + '/editRole',
    method: 'post',
    data
  })
}

export function findAllMenuTree () {
  return request({
    url: api.menu + '/findAllMenuTree',
    method: 'get'
  })
}

export function findMenuByRoleId ({ id }) {
  return request({
    url: api.menu + '/findMenuByRoleId' + `/${id}`,
    method: 'get'
  })
}

export function permissionSetting (data) {
  return request({
    url: api.role + '/permission',
    method: 'post',
    data
  })
}

export function findMenuAndPermissionList () {
  return request({
    url: api.menu + '/findMenuAndPermissionList',
    method: 'get'
  })
}

export function findMenuList (data) {
  return request({
    url: api.menu + '/findMenuList',
    method: 'post',
    data
  })
}

export function checkMenuName (parameter) {
  return request({
    url: api.menu + '/checkMenuName',
    method: 'get',
    params: parameter
  })
}

export function checkMenuKey (parameter) {
  return request({
    url: api.menu + '/checkMenuKey',
    method: 'get',
    params: parameter
  })
}

export function addMenu (data) {
  return request({
    url: api.menu + '/addMenu',
    method: 'post',
    data: data
  })
}

export function delMenu ({ menuId }) {
  return request({
    url: api.menu + '/delMenu' + `/${menuId}`,
    method: 'delete'
  })
}

export function findMenuDetails ({ menuId }) {
  return request({
    url: api.menu + '/findMenuDetails' + `/${menuId}`,
    method: 'get'
  })
}

export function editMenu (data) {
  return request({
    url: api.menu + '/editMenu',
    method: 'put',
    data: data
  })
}

export function findDeptList (data) {
  return request({
    url: api.dept + '/findDeptList',
    method: 'post',
    data
  })
}
